﻿using InfluxData.Net.InfluxDb.Models.Responses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunctionLib.Help
{
    public class QueryHelp
    {
        public static string NumCheck(object param) 
        {
            if (param == null)
            {
                return "参数为空值";
            }
            else if (param.GetType() != typeof(double) && param.GetType() != typeof(int))
            {
                return "参数错误";
            }
            else
            {
                return null;
            }
        }
        public static object GetResult(Serie[] res, ref DateTime time)
        {
            if (res != null && res.Length > 0 &&
                res[0].Values != null && res[0].Values.Count() > 0 &&
                res[0].Values[0] != null && res[0].Values[0].Count() > 1)
            {
                if (res[0].Values[0][0] is DateTime tempTime)
                {
                    time = tempTime;
                }
                return res[0].Values[0][1];
            }
            else
            {
                return double.NaN;
            }
        }
        public static bool IsWithEndEque(int calcType)
        {
            return calcType == 0 || calcType == 5 || calcType == 6;
        }
        public static string GetCalcType(object param, ref int calcType)
        {
            string calcTypeRes = "LAST(Value)";
            if (param != null && (param.GetType() == typeof(double) || param.GetType() == typeof(int)))
            {
                calcType = Convert.ToInt32(param);
                switch (calcType)
                {
                    case 0:
                        calcTypeRes = "SPREAD(Value)";//"LAST(Value) - FIRST(Value)"
                        break;
                    case 1:
                        calcTypeRes = "SUM(Value)";
                        break;
                    case 2:
                        calcTypeRes = "MEAN(Value)";
                        break;
                    case 3:
                        calcTypeRes = "MIN(Value)";
                        break;
                    case 4:
                        calcTypeRes = "MAX(Value)";
                        break;
                    case 5:
                        calcTypeRes = "LAST(Value)";
                        break;
                    case 6:
                        calcTypeRes = "FIRST(Value)";
                        break;
                    case 7:
                        calcTypeRes = "MIN(Value)";
                        break;
                    case 8:
                        calcTypeRes = "MAX(Value)";
                        break;
                    case 9:
                        calcTypeRes = "MIN(Value)";
                        break;
                    case 10:
                        calcTypeRes = "MAX(Value)";
                        break;
                }
            }

            return calcTypeRes;
        }
    }
}
